import { FormProps, FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';
import { Pczt } from '/@/components/Pczt/index';
import { defineComponent, h } from 'vue';
import { useUserStore } from '/@/store/modules/user';
const userStore = useUserStore();
// 公安 --> 城乡结合部重点村综合整治排查 --> 定位 --> 详情
export function tablePopupSchema() {
  return [
    {
      label: '房屋编号',
      field: 'fwbh',
      contentMinWidth: 100,
      labelMinWidth: 60,
    },
    {
      label: '户主姓名',
      field: 'hzxm',
      contentMinWidth: 100,
      labelMinWidth: 60,
    },
    {
      label: '行政区划',
      field: 'add2',
      contentMinWidth: 100,
      labelMinWidth: 60,
    },

    {
      label: '详细地址',
      field: 'address',
      contentMinWidth: 100,
      labelMinWidth: 60,
    },

   
 
    // {
    //   label: '建筑时间',
    //   field: 'build_time',
    //   contentMinWidth: 500,
    //   labelMinWidth: 60,
    // },
  
  ];
}

// 公安 --> 城乡结合部重点村综合整治排查 列表
export function getBasicColumns(): BasicColumn[] {
  const pcztXXX: BasicColumn[] = [];
  if (['FireControl', 'Admin'].includes(userStore.getUserGroup)) {
    pcztXXX.push({
      title: '消防排查状态',
      dataIndex: 'pcztFire',
      width: 200,
      customRender: ({ value }) => {
        return h(Pczt, {
          pcztVal: value,
        });
      },
    });
  }
  if (['Police', 'Admin'].includes(userStore.getUserGroup)) {
    pcztXXX.push({
      title: '公安排查状态',
      dataIndex: 'pcztPolice',
      width: 200,
      customRender: ({ value }) => {
        return h(Pczt, {
          pcztVal: value,
        });
      },
    });
  }
  if (['Housing', 'Admin'].includes(userStore.getUserGroup)) {
    pcztXXX.push({
      title: '房屋排查状态',
      dataIndex: 'pcztHousing',
      width: 200,
      customRender: ({ value }) => {
        return h(Pczt, {
          pcztVal: value,
        });
      },
    });
  }

  let final: BasicColumn[] = [
    {
      title: '编号',
      dataIndex: 'fwbh',
      width: 150,
    },
  ];
  final = final.concat(pcztXXX);
  final = final.concat([
    {
      title: '区县',
      width: 150,
      dataIndex: 'xzqdm',
    },
    {
      title: '乡镇',
      width: 150,
      dataIndex: 'townAlias',
    },
    {
      title: '村庄',
      width: 150,
      dataIndex: 'villageAlias',
    },
    {
      title: '地址',
      dataIndex: 'address',
      width: 300,
    },
    {
      title: '建成时间',
      dataIndex: 'build_time',
    },
    {
      title: '面积',
      width: 150,
      dataIndex: 'dcmj',
    },
    {
      title: '备注',
      dataIndex: 'bz',
    },
    {
      title: '单位名称/小区名称',
      width: 150,
      dataIndex: 'mc',
    },
  ]);

  return final;
}

export function getBasicShortColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      width: 150,
      dataIndex: 'id',
      sorter: true,
      sortOrder: 'ascend',
    },
    {
      title: '所属工程',
      dataIndex: 'project',
      width: 120,
    },
    {
      title: '地理国情分类代码',
      dataIndex: 'cc',
      width: 80,
    },
  ];
}

export function getMultipleHeaderColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 200,
    },
    {
      title: '所属工程',
      dataIndex: 'project',
      width: 120,
    },
  ];
}

export function getCustomHeaderColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 200,
    },
    {
      // title: '姓名',
      dataIndex: 'project',
      width: 120,
      slots: { title: 'customTitle' },
    },
    {
      title: '地理国情分类代码',
      dataIndex: 'cc',
      width: 120,
    },
    {
      title: '创建时间',
      dataIndex: 'createOn',
      width: 120,
    },
    {
      title: '修改时间',
      dataIndex: 'modifiedOn',
      width: 120,
    },
  ];
}
const renderContent = ({ text, index }: { text: any; index: number }) => {
  const obj: any = {
    children: text,
    attrs: {},
  };
  if (index === 9) {
    obj.attrs.colSpan = 0;
  }
  return obj;
};
export function getMergeHeaderColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 300,
      customRender: renderContent,
    },
    {
      title: '所属工程',
      dataIndex: 'project',
      width: 300,
      customRender: renderContent,
    },
    {
      title: '地理国情分类代码',
      dataIndex: 'cc',
      colSpan: 0,
      customRender: renderContent,
    },
    {
      title: '创建时间',
      dataIndex: 'createOn',
      width: 200,
      customRender: renderContent,
    },
    {
      title: '修改时间',
      dataIndex: 'modifiedOn',
      width: 200,
      customRender: renderContent,
    },
  ];
}
export const getAdvanceSchema = (itemNumber = 6): FormSchema[] => {
  const arr: any = [];
  for (let index = 0; index < itemNumber; index++) {
    arr.push({
      field: `field${index}`,
      label: `字段${index}`,
      component: 'Input',
      colProps: {
        xl: 12,
        xxl: 8,
      },
    });
  }
  return arr;
};
export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    schemas: [
      ...getAdvanceSchema(5),
      {
        field: `field11`,
        label: `Slot示例`,
        component: 'Select',
        slot: 'custom',
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
    ],
  };
}
export function getBasicData() {
  const data: any = (() => {
    const arr: any = [];
    for (let index = 0; index < 40; index++) {
      arr.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
      });
    }
    return arr;
  })();
  return data;
}

export function getTreeTableData() {
  const data: any = (() => {
    const arr: any = [];
    for (let index = 0; index < 40; index++) {
      arr.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
        children: [
          {
            id: `l2-${index}`,
            name: 'John Brown',
            age: `1${index}`,
            no: `${index + 10}`,
            address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
            beginTime: new Date().toLocaleString(),
            endTime: new Date().toLocaleString(),
          },
        ],
      });
    }
    return arr;
  })();

  return data;
}
